package net.adriana.component;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;

public class MyList extends JList<Object>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	ListModel<Object> model;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public MyList(String[] contain){
		model =  new DefaultComboBoxModel(contain);
		setBorder(BorderFactory.createEtchedBorder());
		setModel(model);
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	
	public void setLocaAndScroll(MyPanel panel,int x, int y, int width, int height ){
		setBounds(x, y, width, height);
		JScrollPane sp = new JScrollPane();
		sp.setBounds(x,y,width,height);
		sp.setViewportView(this);
		sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		panel.add(sp);
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void setContain(String[] contain){
		model =  new DefaultComboBoxModel(contain);
		setModel(model);
		validate();
	}

}
